import {
    Product
} from "../../public/Product"

//抽象建造者
abstract class Builder {
    public abstract buildPartA(): void
    public abstract buildPartB(): void
    public abstract buildPartC(): void
    public abstract buildProduct(): Product
}

//具体建造者
class ConcreateBuilder extends Builder {
    private _product: Product
    //参数接受具体建造的产品的基类（里氏替换原则）
    constructor(product: Product) {
        super()
        this._product = product
    }
    //建造产品
    public buildProduct(): Product {
        return this._product
    }

    //建造步骤A
    public buildPartA(): void {

    }
    //建造步骤B
    public buildPartB(): void {

    }
    //建造步骤C
    public buildPartC(): void {

    }

}

//具体建造的产品
class ConcreateBuilderProduct extends Product {
    public doSomething(): void {
        //独立业务逻辑
    }
}

//指挥者
class Director {
    private _builder: Builder

    public get builder(): Builder {
        return this._builder
    }

    public set builder(value: Builder) {
        this._builder = value
    }

    constructor(builder: Builder) {
        this._builder = builder
    }

    public buildProduct(): Product {
        //进行构造
        this._builder.buildPartA()
        this._builder.buildPartB()
        this._builder.buildPartC()

        //返回当前产品实例
        return this._builder.buildProduct()
    }

}

const builder: Builder = new ConcreateBuilder(new ConcreateBuilderProduct())
const director: Director = new Director(builder)
const product: ConcreateBuilderProduct = new ConcreateBuilderProduct()

const BuilderTest = ():void =>{
    console.log('product :>> ', product);
}
BuilderTest() 